package main

import "fmt"

/**
 * @author: guangcheng
 * @date:   2020/11/16 17:36
 * @version  V1.0
 * @description:
 *
 */
func BinarySearch(arr *[6]int, leftIndex int, rightIndex int, findVal int) {
	//没有找到
	if leftIndex > rightIndex {
		fmt.Println("错过了, 再也找不到了...")
		return
	}

	middle := (rightIndex-leftIndex)/2 + leftIndex

	if (*arr)[middle] < findVal {
		BinarySearch(arr, middle+1, rightIndex, findVal)
	} else if (*arr)[middle] > findVal {
		BinarySearch(arr, leftIndex, middle-1, findVal)
	} else {
		fmt.Printf("找到了findVal=%v findValIndex=%v", findVal, middle)
	}
}

func main() {
	var arr [6]int = [...]int{1, 2, 3, 4, 5, 6}
	BinarySearch(&arr, 0, 5, 1)
}
